package com.uzhie.web.controller.http;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.uzhie.web.anno.Auth;
import com.uzhie.web.bean.PayloadBean;
import com.uzhie.web.controller.http.comm.CommController;
import com.uzhie.web.module.GpsRecord;
import com.uzhie.web.service.GpsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 位置信息服务
 * Created by lilongfei on 2018/8/2.
 */
@Controller
@RequestMapping(value = "position")
public class PositionController extends CommController {

    @Autowired
    private GpsService gpsService;

    /**
     * 通过sim卡号集合获取位置信息
     *
     * @param body sim卡集合
     * @return
     */
    @Auth
    @ResponseBody
    @RequestMapping(value = "getPosition")
    public PayloadBean getPosition(@RequestBody(required = false) JSONObject body) {
        List<String> params = JSONArray.parseArray(body.getJSONArray("sims").toJSONString(), String.class);
        List<GpsRecord> result = gpsService.queryListBySimList(params);
        if (result != null && result.size() > 0) return buildResponse(result);
        else return buildResponse(null, "没有位置信息");
    }
}
